<?php

use Illuminate\Database\Seeder;
use Carbon\Carbon;


class FakerUserTableSeeder extends Seeder
{

    /**
     * Auto generated seed file
     *
     * @return void
     */
    public function run()
    {

        Eloquent::unguard();

//        \DB::table('users')->delete();
//        \DB::table('user_extensions')->delete();

        $faker = Faker\Factory::create('zh_CN');
        static $password;





        foreach ($this->makeRange(100) as $i) {
//            echo $i . PHP_EOL;
//            echo $i;

            $userName = $faker->userName;
            $time = Carbon::now('Asia/Chongqing');

            $id = DB::table('users')->insertGetId(
                [
                    'name' => $userName,
                    'email' => $faker->unique()->safeEmail,
                    'password' => $password ?: $password = bcrypt('secret'),
//                    'password' => bcrypt('secret'),
                    'remember_token' => str_random(10),
                    'created_at' => $time,
                    'updated_at' => $time
                ]
            );


            DB::table('user_extensions')->insert(
                [
                    'user_id' => $id,
                    'nickname' => $faker->name,
                    'wechat' => 'wechat_'.$userName,
                    'qq' => $faker->randomNumber(9),
                    'phone' => $faker->phoneNumber,
//                    'phone' => $faker->phoneNumber,
                    'sex' => '0',
                    'status' => '0'
                ]
            );

        }














//        \DB::table('users')->delete();
//
//        \DB::table('users')->insert(array (
//            0 =>
//                array (
//                    'id' => 1,
//                    'name' => 'Federico Larkin',
//                    'email' => 'agleichner@example.com',
//                    'password' => '$2y$10$/eUoZFHnZHXEtdazSoO0YOSCrPaqwLMldm/qAg7k8GW3S5dgY1zq2',
//                    'remember_token' => 'wezDJWapGa',
//                    'created_at' => '2017-05-18 02:36:03',
//                    'updated_at' => '2017-05-18 02:36:03',
//                ),
//            1 =>
//                array (
//                    'id' => 2,
//                    'name' => 'Tracy Veum',
//                    'email' => 'eldridge29@example.org',
//                    'password' => '$2y$10$/eUoZFHnZHXEtdazSoO0YOSCrPaqwLMldm/qAg7k8GW3S5dgY1zq2',
//                    'remember_token' => 'jRV0dcTHXv',
//                    'created_at' => '2017-05-18 02:36:41',
//                    'updated_at' => '2017-05-18 02:36:41',
//                ),
//            2 =>
//                array (
//                    'id' => 8,
//                    'name' => 'yafei03',
//                    'email' => 'yafei03@qq.com',
//                    'password' => '$2y$10$wHaR.RXwVEj2sXCxnCT8XeVX9TkgzLeEHyJ9FYw2hB/nZ0CJ.LzJu',
//                    'remember_token' => NULL,
//                    'created_at' => '2017-05-22 15:39:19',
//                    'updated_at' => '2017-05-22 15:39:19',
//                ),
//            3 =>
//                array (
//                    'id' => 10,
//                    'name' => 'wangge',
//                    'email' => 'wangge@pxsj.com',
//                    'password' => '$2y$10$vlZ4ag1ETWRJTq6Xoe3x1.Jpmj7y95ugqVlCcv.bJAsNO2.DUp6M.',
//                    'remember_token' => NULL,
//                    'created_at' => '2017-05-23 03:24:31',
//                    'updated_at' => '2017-05-23 03:24:31',
//                ),
//            4 =>
//                array (
//                    'id' => 11,
//                    'name' => 'ouyafei',
//                    'email' => 'ouyafei@pxsj.com',
//                    'password' => '$2y$10$LVfPX2RAfsEikjPGekpOOOhaE8S.igvEyxp1cfzuMNEcF5so2KSV6',
//                    'remember_token' => NULL,
//                    'created_at' => '2017-05-23 09:05:58',
//                    'updated_at' => '2017-05-23 09:05:58',
//                ),
//            5 =>
//                array (
//                    'id' => 12,
//                    'name' => 'yichunguang',
//                    'email' => 'yichunguang@pxsj.com',
//                    'password' => '$2y$10$teu48RjWgXuxFyAuFshkIuUEAv5KhUZnWzaiDJ8uQHv/5LKIsgxKO',
//                    'remember_token' => 'mDRwYgV8z3BG8KJIiBxzPqYdkQEYfis2UxKssEdtffVE05U3jfOxIzIFHz1P',
//                    'created_at' => '2017-05-24 05:40:04',
//                    'updated_at' => '2017-05-24 05:40:04',
//                ),
//            6 =>
//                array (
//                    'id' => 13,
//                    'name' => 'guanli01',
//                    'email' => 'guanli01@pxsj.com',
//                    'password' => '$2y$10$RbvBSkRu.2VsaMBKYXGtKuItPu98.2dxQvdt6FY7xvC1blyapdfSO',
//                    'remember_token' => 'RYyjXh46NvysXwXRpTDJ9DM1Jg5T62TPM6RWtuXxB8iQo8ufx8KxlVdi2dxT',
//                    'created_at' => '2017-05-24 06:45:28',
//                    'updated_at' => '2017-05-24 06:45:28',
//                ),
//            7 =>
//                array (
//                    'id' => 14,
//                    'name' => 'admin01',
//                    'email' => 'admin@pxsj.com',
//                    'password' => '$2y$10$PPBTkiFPhDfQ0V6kP86TK.xszKLpdXa54OxTsy5VVxRi/a9qPu4Dq',
//                    'remember_token' => NULL,
//                    'created_at' => '2017-05-24 06:45:49',
//                    'updated_at' => '2017-05-24 06:45:49',
//                ),
//        ));




    }

    public function makeRange($length) {
        for ($i = 0; $i < $length; $i++) {
            yield $i;
        }
    }

}